import { useEidSaveStore } from '@/stores';
import { http } from '@/utils/http';
import type { Data } from './types/user';

export const requestLonging = async () => {
  const eidName = useEidSaveStore().getEidSave().userName;
  const eid = await searchUser(eidName);

  if (eid) {
    return http<Data>({
      url: '/api/user/login',
      method: 'POST',
      data: {
        isEnterpriseVerification: true,
        mRawIdToken:
          'eyJhbGciOiJSUzI1NiIsImtpZCI6IkpselRHRXBBcHlvVEFScGplM2tBUkY5bzRKaksydHpyNEdiaUJMR3J6cFkiLCJ0eXAiOiJKV1QifQ.eyJ2ZXIiOiIxLjAiLCJpc3MiOiJodHRwczovL2Vjb2xhYmIyYy5iMmNsb2dpbi5jb20vMjc4YThlNDItOWE3Ny00NDJjLTg5OWItMWUzMjEyMDJjZDA0L3YyLjAvIiwic3ViIjoiNjljYWRjMWYtZDZiMy00ODlkLTg5MDctODhiZjkxNGMxOTVmIiwiYXVkIjoiNWI0YjcxYjAtYmVhOC00ODZGMxZi1kNmIzLTZlLThhMzEtMTc0OTk1OGUzYTI5IiwiZXhwIjoxNzA2NjMxNDI5LCJhY3IiOiJiMmNfMWFfZG9tYWluX2hpbnQiLCJpYXQiOjE3MDY2Mjc4MjksImF1dGhfdGltZSI6MTcwNjYyNzgyNywiaWRwIjoibWFycmlvdHQuY29tIiwiaXNzdWVyVXNlcklkIjoiY2NhaTMyM0BtYXJyaW90dC5jb20iLCJvaWQiOiI2OWNhQ4OWQtODkwNy04OGJmOTE0YzE5NWYiLCJNYW5hZ2VkVXNlcm5hbWUiOiJjY2FpMzIzQG1hcnJpb3R0LmNvbSIsIkNvcnJlbGF0aW9uSWQiOiI0ZjM2YzdkYi1hMWNkLTQ1YTQtYWJmNi0wNDRiZjc3ZWM5NDQiLCJhdF9oYXNoIjoiR2NyMjZTRjNjOGptbDZfSUdxY3lqQSIsIm5iZiI6MTcwNjYyNzgyOX0.gjD5H64Gl-y559T3GJVgp974MbYabQmpyIvGX1O08fYdJ_a5yetsJ14BGWCzKcuAlWn5r3rDzatjfxtmLRtPABAqpmT_8As6lCM97Fikl9WywS4aZNTVoniKFTEdr7XoOF6xVew2Me1vvIVNCSsRvhoCfMqBB0eEKvG1eY2mclJQ382ycA3nFaynq-JOESAKozxv468QfZLb1EGKD4xkJH2o-jsFXAcOAOlSbrR0TW4eAJkLTa42YhFgRh2Y13xyhuV1wCVSWQgztmzznRIFji8mzGZZxDm3jMnrmzvTFP1g-z7NyHO0rTR0fBKFFwPc6HaVHXNq-U9aGVrtm1D0sn',
        mobile: eid.data.userNameList[0].username,
        password: 'e10adc3949ba59abbe56e057f20f883e',
        pushToken: '100d8559084744d7619',
      },
    });
  } else {
    uni.showToast({ title: '请输入完整EID信息', icon: 'none' });
    setTimeout(() => {
      uni.navigateTo({ url: '/pages/eidSetting/eidSetting' });
    }, 1000);
  }
};

const searchUser = async (eid: string) => {
  return await http<{
    userNameList: {
      realName?: string;
      username?: string;
    }[];
  }>({
    url: '/api/user/selectUserByEid',
    method: 'POST',
    data: {
      eid: eid + '@marriott.com',
    },
  });
};
